package com.baichang.taoshunda.controller;


import com.baichang.framework.controller.BaseController;
import com.baichang.framework.controller.IController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.service.EasemobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 环信调用的接口
 * Created by Dylan on 2015/12/9.
 */
@Controller
@RequestMapping("/easemob")
public class EasemobController extends BaseController {

    @Autowired
    EasemobService easemobService;

    /**
     * 环信调用的登录接口
     *
     * @param request
     * @param response
     */
    @RequestMapping("hxLogin")
    public void hxLogin(HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest request, HttpServletResponse response) throws ServiceException {
                String userName = ServletRequestUtils.getStringParameter(request, "userName", "");
                String userPwd = ServletRequestUtils.getStringParameter(request, "userPwd", "");
                Integer userType = ServletRequestUtils.getIntParameter(request, "userType", -1);
                return easemobService.login(userName, userPwd, userType);
            }
        });

    }

    /**
     * 环信调用的登录接口
     *
     * @param request
     * @param response
     */
    @RequestMapping("hxLogin2")
    public void hxLogin2(HttpServletRequest request, HttpServletResponse response) {

        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest request, HttpServletResponse response) throws ServiceException {
                String userName = ServletRequestUtils.getStringParameter(request, "userName", "");
                String userPwd = ServletRequestUtils.getStringParameter(request, "userPwd", "");
                Integer userType = ServletRequestUtils.getIntParameter(request, "userType", -1);
                return easemobService.login2(userName, userPwd, userType);
            }

        });
    }


}



